package com.example.backend.mapper;

import com.example.backend.entity.Book;
import com.example.backend.entity.Post;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface PostMapper {
    //显示所有帖子
    @Select("select * from posts join users u on posts.userId = u.userId")
    List<Post> getAllPosts();

    //增加帖子
    @Insert("insert into posts (postId,userId,title,content,date)   values(#{postId},#{userid},#{title},#{content},#{date})")
    int addPosts(@Param("postId") int postId, @Param("userid") int userId, @Param("title") String title, @Param("content") String content, @Param("date") String date);

    //查找帖子
    @Select("select * from posts join users u on posts.userId = u.userId where title=#{title}")
    List<Post> getPosts(@Param("title") String title);

    //删除帖子
    @Delete("delete from posts where postId = #{postId}")
    int deletePosts(@Param("postId") int id);

    //修改帖子
    @Update("update posts set userId = #{userId},title = #{title},content = #{content},date = #{date} where postId = #{postId}")
    int updatePosts(@Param("postId") int id,@Param("userId") int id2,@Param("title") String title,@Param("content") String content,@Param("date") String date);
}
